package ch.ethz.group3.myalbum.client.utils;

import ch.ethz.group3.myalbum.client.ImageOnlyWindow;
import ch.ethz.group3.myalbum.client.ImageTileRecord;
import ch.ethz.group3.myalbum.client.ImageWindow;
import ch.ethz.group3.myalbum.client.LoginWindow;
import ch.ethz.group3.myalbum.shared.AuthorizationModel;

import com.smartgwt.client.types.AnimationEffect;
import com.smartgwt.client.util.SC;

public class Notifier {
	private static final LoginWindow loginWindow;
	private static final ImageWindow imageWindow;
	private static final ImageOnlyWindow imageOnlyWindow;
	
	static {
		imageOnlyWindow = new ImageOnlyWindow();
		imageOnlyWindow.show();
		imageOnlyWindow.hide();
		
		imageWindow = new ImageWindow();
		imageWindow.init();
		imageWindow.show();
		imageWindow.hide();
		
		loginWindow = new LoginWindow();
	}
	
	public static void notify(AuthorizationModel e) {
		Global.requestToken = e.getRequetToken();
		com.google.gwt.user.client.Window.open(e.getAuthorizationUrl(), "Authorization_URL",
		           "menubar=no," + 
		           "location=false," + 
		           "resizable=yes," + 
		           "scrollbars=yes," + 
		           "status=no," + 
		           "dependent=true,width=640,height=400");
		loginWindow.animateShow(AnimationEffect.SLIDE);
	}
	
	public static void showImage(ImageTileRecord image) {
		if (image.getCommentCount() > 0) {
			imageWindow.showImage(image);
			imageWindow.animateShow(AnimationEffect.SLIDE);
		} else {
			imageOnlyWindow.showImage(image);
			imageOnlyWindow.animateShow(AnimationEffect.SLIDE);
		}
	}
	
}
